package cn.szsys.integration.controller;

import cn.szsys.integration.constants.AppConstant;
import cn.szsys.integration.dto.EconomicCapabilityDTO;
import cn.szsys.integration.helper.BusinessBeanNameConstant;
import cn.szsys.integration.helper.manager.EconomicCapabilityForwardHandlerChainManager;
import cn.szsys.integration.util.R;
import jakarta.servlet.http.HttpServletRequest;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import java.util.Objects;

/**
 * 经济能力评估
 */
@RestController
@RequestMapping("/economy")
@RequiredArgsConstructor
public class EconomicCapabilityAssessmentController {

    private final EconomicCapabilityForwardHandlerChainManager economicCapabilityForwardHandlerChainManager;

    /**
     * @param dto dto
     * @return {@link R}
     * @author Ryan
     */
    @PostMapping("/person")
    public R personData(@RequestBody @Validated EconomicCapabilityDTO dto) {
        ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = requestAttributes.getRequest();
        String downstream = request.getHeader(AppConstant.DOWNSTREAM_ABBREVIATION);
        if (Objects.equals(downstream, "weichengzhengxin")){
            return economicCapabilityForwardHandlerChainManager.handler(dto, BusinessBeanNameConstant.EconomicCapability.VD_ECONOMIC_CAPABILITY_HANDLER_CHAIN);
        }
        return economicCapabilityForwardHandlerChainManager.handler(dto, BusinessBeanNameConstant.EconomicCapability.ZXYR_ECONOMIC_CAPABILITY_HANDLER_CHAIN);
    }
}
